#ifndef DOUBAN_DOUMAIL_MAILMODULE_P_H
#define DOUBAN_DOUMAIL_MAILMODULE_P_H

#include "douban_global.h"
#include "MailModule.h"
#include "MailViewer.h"
#include "MailCreator.h"
#include "DoumailModel.h"
#include <QXmlStreamReader>
#include <QPushButton>
#include <QTreeView>
#include <QPointer>
#include <QFrame>
#include <QLabel>
#include <QTimer>
class QNetworkReply;
class QEvent;

namespace Douban
{
	class MailModulePrivate : public QObject
	{
		Q_OBJECT
		public:
			void setUpdateInterval(int millsec);
		private:
			int				i_unreadCount;
			bool			b_autoCloseDialog;
			Doumails		m_inbox;
			MailModule*		m_pImpl;
			DoubanContext*	m_context;
			DoumailModel	m_mailModel;
			MailViewer		m_mailViewer;
			MailCreator		m_mailCreator;
			QTimer			m_updateTimer;
			QXmlStreamReader xmlParser;

			QWidget*		m_mailWidget;
			QFrame			m_btnFrame;
			QPushButton		m_goWebBtn;
			QTreeView		m_treeView;
			QLabel			m_noNewLabel;
			QNetworkReply*	r_inboxReply;
		public:
			~MailModulePrivate();
			bool eventFilter(QObject*, QEvent*);
			static void notifyCB(QObject*,const QString&);
			static void notifyCB2(QObject*,const QString&);
			void notifyCallBack();
			void notifyCallBack2();
		private slots:
			void checkUnread();
			void viewMail(const QModelIndex&);
			void checkUnreadFinished();
			void goWeb();
		private:
			static const quint32 MagicNumber;
			static const QString Doumail_Unread_URL;
			static const QString MailDelimeter;

			void updateWidget();
			void readLocalData();
			MailModulePrivate(MailModule*,DoubanContext*,QWidget*);
			Q_DISABLE_COPY(MailModulePrivate)
		friend class MailModule;
	};
}

#endif /* MAILMODULE_P_H_ */
